<div class="layui-card layadmin-header">
    <div class="layui-breadcrumb" lay-filter="breadcrumb">
        <a lay-href="">主页</a>
        <a>结算</a>
        <a><cite>结算记录</cite></a>
    </div>
</div>
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-tab layui-tab-brief">
            <ul class="layui-tab-title">
                <li class="layui-this">结算记录</li>
            </ul>
            <div class="layui-tab-content">
                <div class="layui-tab-item layui-show" style="margin-bottom:1%;">
                    <div class="layui-row">
                        <div class="layui-form" style="float:right;">
                            <div class="layui-form-item" style="margin:0;">
                                <div class="layui-input-inline">
                                    <input type="text" name="id" id="id" placeholder="流水号" autocomplete="off" class="layui-input">
                                </div>
                                <div class="layui-input-inline">
                                    <input type="text" name="mchId" id="mchId" placeholder="商户ID" autocomplete="off" class="layui-input">
                                </div>
                                <div class="layui-input-inline">
                                    <select name="settStatus" id="settStatus" lay-search="">
                                        <option value="-99">状态</option>
                                        <option value="1">等待审核</option>
                                        <option value="2">已审核</option>
                                        <option value="3">审核不通过</option>
                                        <option value="4">打款中</option>
                                        <option value="5">打款成功</option>
                                        <option value="6">打款失败</option>
                                    </select>
                                </div>
                                <button id="search" class="layui-btn" data-type="reload">
                                    <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                                </button>
                            </div>
                        </div>
                    </div>
                </div>
                <table id="jsList" lay-filter="jsList"></table>
            </div>
        </div>
    </div>
</div>

<script type="text/html" id="payBar">
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">查看</a>
    <a class="layui-btn layui-btn-xs" lay-event="edit">账户列表</a>
</script>
<script>


     layui.use(['table','util','element','form','admin','layedit'], function(){
        var table = layui.table
            ,$ = layui.$
            ,form = layui.form
            ,view =layui.view,
            admin=layui.admin,
            layedit=layui.layedit,
            layer =layui.layer
        ,element = layui.element;

        element.render('breadcrumb', 'breadcrumb');//渲染导航信息

         var tplStatus = function(d){
             if(d.settStatus == 1) {
                 return "<span style='color: red'>等待审核</span>";
             }else if(d.settStatus == 2) {
                 return "<span style='color: darkgreen'>已审核</span>";
             }else if(d.settStatus == 3) {
                 return "<span style='color: indigo'>审核不通过</span>";
             }else if(d.settStatus == 4) {
                 return "<span style='color: blue'>打款中</span>";
             }else if(d.settStatus == 5) {
                 return "<span style='color: brown'>打款成功</span>";
             }else if(d.settStatus == 6) {
                 return "<span style='color: #122b40'>打款失败</span>";
             }
         };


         table.render({
            elem: '#jsList'
            ,url: layui.setter.baseUrl + '/sett/list'
            ,where: {
                access_token: layui.data(layui.setter.tableName).access_token
            }
            ,id: 'tableReload'
            ,cols: [[
                {field:'id', title: '流水号', sort: true }
                ,{field:'mchId', title: '商户ID', sort: true }
                ,{field: 'settMode',title: '结算发起方式',templet: '<div>{{d.settMode == 1?"手工结算":"自动结算"}}</div>'}
                ,{field: 'mchType',title: '账户类型',templet: '<div>{{d.mchType == 1?"平台账户":"私有账户"}}</div>'}
                ,{field: 'settDate',title: '结算日期',templet: '<div>{{ layui.util.toDateString(d.settDate, "yyyy-MM-dd") }}</div>'}
                ,{field:'settAmount', title: '结算金额',templet: '<div>{{d.settAmount/100}}</div>' }
                ,{field: 'settStatus',title: '结算状态',templet: tplStatus}
                ,{field:'createTime',  title: '时间', templet: '<div>{{ layui.util.toDateString(d.createTime) }}</div>' }
                ,{field:'edite', title: '操作',width:320,toolbar:'#payBar' }
            ]]
            ,page: true
            ,skin: 'line'
        });

         table.on('tool(jsList)', function(obj){
             var data = obj.data;
             console.log(data)
             if(obj.event === 'detail'){
                 var id =data.id;
                 admin.req({
                     type: 'get',
                     url: layui.setter.baseUrl + '/sett/get',
                     data: {
                         id: id
                     },
                     success: function(res){
                         if(res.code == 0){

                             data =res.data;
                             admin.popup({
                                 title: '结算详情'
                                 , area: ['800px', '615px']
                                 , id: 'LAY-popup-content-detail'
                                 , success: function (layero, index) {
                                     view(this.id).render('sett/detail').done(function () {
                                         form.render(null, 'layuiadmin-app-form-list');

                                         var body =layer.getChildFrame('body',index);
                                         body.find('#email').val(data.email);
                                         form.val("layuiadmin-app-form-list",{
                                             "id":res.data.id,
                                             "mchId":data.mchId,
                                             "name":res.data.name,
                                             "settMode":res.data.settMode==1?"手工结算":"自动结算",
                                             "mchType":res.data.mchType==1?"平台账户":"私有账户",
                                             "settDate":layui.util.toDateString(res.data.settDate, "yyyy-MM-dd"),
                                             "settAmount":res.data.settAmount,
                                             "remitAmount":res.data.remitAmount,
                                             "remitType":res.data.remitType==1?"银行转账":res.data.remitType==2?"微信转账":res.data.remitType==3?"支付宝转账":"非法类型",
                                             "mchRemitInfo":res.data.mchRemitInfo,
                                             "settFee":res.data.settFee/100,
                                             "settStatus":res.data.settStatus == 1?"等待审核":res.data.settStatus == 2?"已审核":res.data.settStatus == 3?"审核不通过":res.data.settStatus == 4?"打款中":res.data.settStatus == 5?"打款成功":res.data.settStatus == 6?"打款失败":"非法结算状态",
                                             "operatorName":res.data.operatorName,
                                             "operatorId":res.data.operatorId == null ? "" : res.data.operatorId,
                                             "remitRemark":res.data.remitRemark,
                                             "remark":res.data.remitRemark,
                                             "createTime":layui.util.toDateString(res.data.createTime),
                                             "updateTime":layui.util.toDateString(res.data.updateTime)
                                         })

                                     });
                                 }
                             });
                         }else {
                             layer.alert(res.msg,{
                                 title: '请求成功，但是状态不对'
                             })
                         }
                     }
                 })




             } else if(obj.event === 'edit'){
                 location.href = layui.setter.baseLocal + "sett/batch/id=" + data.id;
             }
         });





      
        // 搜索
        var $ = layui.$, active = {
            reload: function(){
                var id = $('#id').val();
                var mchId = $("#mchId").val();
                var settStatus = $("#settStatus").val();
                //执行重载
                table.reload('tableReload', {
                    page: {
                        curr: 1 //重新从第 1 页开始
                    }
                    ,where: {
                        id: id,
                        mchId : mchId,
                        settStatus : settStatus
                    }
                });
            }
        };
        $('#search').on('click', function() {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });


        // 渲染表单
        form.render();

        
     })

</script>